<!-- build time:Mon Feb 17 2020 20:58:01 GMT+0800 (GMT+08:00) --><!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=5"><title>分布式文件系统FastDFS安装部署(高可用) | MaxBill</title><meta name="description" content="分布式文件系统FastDFS安装部署(高可用)"><meta name="keywords" content="FastDFS,分布式文件系统,高可用"><meta name="author" content="MaxBill"><meta name="copyright" content="MaxBill"><meta name="format-detection" content="telephone=no"><link rel="shortcut icon" href="https://cdn.maxbill.cn/blog/img/favicon.ico"><link rel="preconnect" href="//cdn.jsdelivr.net"><link rel="preconnect" href="https://hm.baidu.com"><link rel="preconnect" href="https://fonts.googleapis.com" crossorigin><link rel="preconnect" href="//busuanzi.ibruce.info"><meta name="baidu-site-verification" content="2Uh0QVZKT2"><meta name="360-site-verification" content="b1208ccd98a16e82d8c052bce2070c57"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="分布式文件系统FastDFS安装部署(高可用)"><meta name="twitter:description" content="分布式文件系统FastDFS安装部署(高可用)"><meta name="twitter:image" content="https://cdn.maxbill.cn/post/cover/fastdfs.jpg"><meta property="og:type" content="article"><meta property="og:title" content="分布式文件系统FastDFS安装部署(高可用)"><meta property="og:url" content="https://www.maxbill.cn/4293262294"><meta property="og:site_name" content="MaxBill"><meta property="og:description" content="分布式文件系统FastDFS安装部署(高可用)"><meta property="og:image" content="https://cdn.maxbill.cn/post/cover/fastdfs.jpg"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><script src="https://cdn.maxbill.cn/blog/js/js.cookie.min.js"></script><script>function activateDarkMode(){document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#000")}function activateLightMode(){document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#fff")}const autoChangeMode="false";var t=Cookies.get("theme");const isDarkMode,isLightMode,isNotSpecified,hasNoSupport;"dark"==t?activateDarkMode():"light"==t&&activateLightMode()</script><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="https://cdn.maxbill.cn/blog/css/fancybox.min.css"><link rel="stylesheet" href="https://cdn.maxbill.cn/blog/css/snackbar.min.css"><link rel="canonical" href="https://www.maxbill.cn/4293262294"><link rel="prev" title="使用Hexo写第一篇文章" href="https://www.maxbill.cn/3439513514.html"><link rel="next" title="分布式文件系统FastDFS安装部署(非高可用)" href="https://www.maxbill.cn/2128340410.html"><script>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?1dca1d7758230e43dd5a9504001c33fc";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web"><script>var GLOBAL_CONFIG={root:"/",algolia:void 0,localSearch:{path:"search.xml",languages:{hits_empty:"找不到您查询的内容:${query}"}},translate:{defaultEncoding:2,translateDelay:0,cookieDomain:"https://www.maxbill.cn/",msgToTraditionalChinese:"繁",msgToSimplifiedChinese:"简"},copy:{success:"复制成功",error:"复制错误",noSupport:"浏览器不支持"},bookmark:{title:"Snackbar.bookmark.title",message_prev:"按",message_next:"键将本页加入书签"},runtime_unit:"天",runtime:!0,copyright:void 0,ClickShowText:void 0,medium_zoom:!1,fancybox:!0,Snackbar:{bookmark:{title:"Snackbar.bookmark.title",message_prev:"按",message_next:"键将本页加入书签"},chs_to_cht:"你已切换为繁体",cht_to_chs:"你已切换为简体",day_to_night:"你已切换为深色模式",night_to_day:"你已切换为浅色模式",bgLight:"#49b1f5",bgDark:"#2d3035",position:"bottom-left"},baiduPush:!0,isHome:!1,isPost:!0}</script><meta name="generator" content="Hexo 4.2.0"><link rel="alternate" href="/atom.xml" title="MaxBill" type="application/atom+xml"></head><body><header><div id="page-header"><span class="pull_left" id="blog_name"><a class="blog_title" id="site-name" href="/">MaxBill</a></span><span class="toggle-menu pull_right close"><a class="site-page"><i class="fa fa-bars fa-fw" aria-hidden="true"></i></a></span><span class="pull_right menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/packs/"><i class="fa-fw fa-fw fa fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/marks/"><i class="fa-fw fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/kinds/"><i class="fa-fw fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/speak/"><i class="fa-fw fa-fw fa fa-wechat"></i><span> 微言</span></a></div><div class="menus_item"><a class="site-page" href="/words/"><i class="fa-fw fa-fw fa fa-coffee"></i><span> 留言</span></a></div><div class="menus_item"><a class="site-page" href="/vitae/"><i class="fa-fw fa-fw fa fa-address-card"></i><span> 简历</span></a></div><div class="menus_item"><a class="site-page" href="/links/"><i class="fa-fw fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa-fw fa fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page"><i class="fa-fw fa-fw fa fa-list" aria-hidden="true"></i><span> 其他</span><i class="fa fa-chevron-down menus-expand" aria-hidden="true"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/music/"><i class="fa-fw fa-fw fa fa-file-audio-o"></i><span> 音乐</span></a></li><li><a class="site-page" href="/image/"><i class="fa-fw fa-fw fa fa-file-image-o"></i><span> 照片</span></a></li><li><a class="site-page" href="/tools/"><i class="fa-fw fa-fw fa fa-file-code-o"></i><span> 工具</span></a></li></ul></div></div></span><span class="pull_right" id="search_button"><a class="site-page social-icon search"><i class="fa fa-search fa-fw"></i><span> 搜索</span></a></span></div></header><div id="mobile-sidebar"><div id="menu_mask"></div><div id="mobile-sidebar-menus"><div class="mobile_author_icon"><img class="avatar-img" src="https://cdn.maxbill.cn/blog/img/avatar.png" onerror='onerror=null,src="https://cdn.maxbill.cn/blog/img/link-404.gif"' alt="avatar"></div><div class="mobile_post_data"><div class="mobile_data_item is-center"><div class="mobile_data_link"><a href="/packs/"><div class="headline">文章</div><div class="length_num">24</div></a></div></div><div class="mobile_data_item is-center"><div class="mobile_data_link"><a href="/marks/"><div class="headline">标签</div><div class="length_num">46</div></a></div></div><div class="mobile_data_item is-center"><div class="mobile_data_link"><a href="/kinds/"><div class="headline">分类</div><div class="length_num">6</div></a></div></div></div><hr><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/packs/"><i class="fa-fw fa-fw fa fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/marks/"><i class="fa-fw fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/kinds/"><i class="fa-fw fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/speak/"><i class="fa-fw fa-fw fa fa-wechat"></i><span> 微言</span></a></div><div class="menus_item"><a class="site-page" href="/words/"><i class="fa-fw fa-fw fa fa-coffee"></i><span> 留言</span></a></div><div class="menus_item"><a class="site-page" href="/vitae/"><i class="fa-fw fa-fw fa fa-address-card"></i><span> 简历</span></a></div><div class="menus_item"><a class="site-page" href="/links/"><i class="fa-fw fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa-fw fa fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page"><i class="fa-fw fa-fw fa fa-list" aria-hidden="true"></i><span> 其他</span><i class="fa fa-chevron-down menus-expand" aria-hidden="true"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/music/"><i class="fa-fw fa-fw fa fa-file-audio-o"></i><span> 音乐</span></a></li><li><a class="site-page" href="/image/"><i class="fa-fw fa-fw fa fa-file-image-o"></i><span> 照片</span></a></li><li><a class="site-page" href="/tools/"><i class="fa-fw fa-fw fa fa-file-code-o"></i><span> 工具</span></a></li></ul></div></div></div><div id="mobile-sidebar-toc"><div class="toc_mobile_headline">目录</div><div class="sidebar-toc__content"><ol class="toc_mobile_items"><li class="toc_mobile_items-item toc_mobile_items-level-2"><a class="toc_mobile_items-link" href="#FastDFS简介"><span class="toc_mobile_items-number">1.</span> <span class="toc_mobile_items-text">FastDFS简介</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-2"><a class="toc_mobile_items-link" href="#FastDFS原理介绍"><span class="toc_mobile_items-number">2.</span> <span class="toc_mobile_items-text">FastDFS原理介绍</span></a><ol class="toc_mobile_items-child"><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#文件上传"><span class="toc_mobile_items-number">2.1.</span> <span class="toc_mobile_items-text">文件上传</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#文件同步"><span class="toc_mobile_items-number">2.2.</span> <span class="toc_mobile_items-text">文件同步</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#下载文件"><span class="toc_mobile_items-number">2.3.</span> <span class="toc_mobile_items-text">下载文件</span></a></li></ol></li><li class="toc_mobile_items-item toc_mobile_items-level-2"><a class="toc_mobile_items-link" href="#部署环境准备"><span class="toc_mobile_items-number">3.</span> <span class="toc_mobile_items-text">部署环境准备</span></a><ol class="toc_mobile_items-child"><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#环境说明"><span class="toc_mobile_items-number">3.1.</span> <span class="toc_mobile_items-text">环境说明</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#系统依赖"><span class="toc_mobile_items-number">3.2.</span> <span class="toc_mobile_items-text">系统依赖</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#软件环境"><span class="toc_mobile_items-number">3.3.</span> <span class="toc_mobile_items-text">软件环境</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#机器及网络环境规划"><span class="toc_mobile_items-number">3.4.</span> <span class="toc_mobile_items-text">机器及网络环境规划</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#防火墙设置"><span class="toc_mobile_items-number">3.5.</span> <span class="toc_mobile_items-text">防火墙设置</span></a></li></ol></li><li class="toc_mobile_items-item toc_mobile_items-level-2"><a class="toc_mobile_items-link" href="#Keepalived服务安装配置"><span class="toc_mobile_items-number">4.</span> <span class="toc_mobile_items-text">Keepalived服务安装配置</span></a><ol class="toc_mobile_items-child"><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#下载Keepalived源码包"><span class="toc_mobile_items-number">4.1.</span> <span class="toc_mobile_items-text">下载Keepalived源码包</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#上传并解压Keepalived源码包"><span class="toc_mobile_items-number">4.2.</span> <span class="toc_mobile_items-text">上传并解压Keepalived源码包</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#编译Keepalived准备"><span class="toc_mobile_items-number">4.3.</span> <span class="toc_mobile_items-text">编译Keepalived准备</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#编译安装Keepalived"><span class="toc_mobile_items-number">4.4.</span> <span class="toc_mobile_items-text">编译安装Keepalived</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#安装配置Keepalived"><span class="toc_mobile_items-number">4.5.</span> <span class="toc_mobile_items-text">安装配置Keepalived</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#设置Keepalived开机启动项"><span class="toc_mobile_items-number">4.6.</span> <span class="toc_mobile_items-text">设置Keepalived开机启动项</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#配置Keepalived服务"><span class="toc_mobile_items-number">4.7.</span> <span class="toc_mobile_items-text">配置Keepalived服务</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#编写nginx服务检测脚本"><span class="toc_mobile_items-number">4.8.</span> <span class="toc_mobile_items-text">编写nginx服务检测脚本</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#修改内核参数"><span class="toc_mobile_items-number">4.9.</span> <span class="toc_mobile_items-text">修改内核参数</span></a></li></ol></li><li class="toc_mobile_items-item toc_mobile_items-level-2"><a class="toc_mobile_items-link" href="#安装FastDFS依赖库"><span class="toc_mobile_items-number">5.</span> <span class="toc_mobile_items-text">安装FastDFS依赖库</span></a><ol class="toc_mobile_items-child"><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#安装libevent依赖"><span class="toc_mobile_items-number">5.1.</span> <span class="toc_mobile_items-text">安装libevent依赖</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#安装libfasttcommon依赖"><span class="toc_mobile_items-number">5.2.</span> <span class="toc_mobile_items-text">安装libfasttcommon依赖</span></a></li></ol></li><li class="toc_mobile_items-item toc_mobile_items-level-2"><a class="toc_mobile_items-link" href="#安装部署Tracker服务和Storage服务"><span class="toc_mobile_items-number">6.</span> <span class="toc_mobile_items-text">安装部署Tracker服务和Storage服务</span></a><ol class="toc_mobile_items-child"><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#安装fastdfs服务"><span class="toc_mobile_items-number">6.1.</span> <span class="toc_mobile_items-text">安装fastdfs服务</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#fastdfs服务目录信息"><span class="toc_mobile_items-number">6.2.</span> <span class="toc_mobile_items-text">fastdfs服务目录信息</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#注册开机启动"><span class="toc_mobile_items-number">6.3.</span> <span class="toc_mobile_items-text">注册开机启动</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#数据目录规划"><span class="toc_mobile_items-number">6.4.</span> <span class="toc_mobile_items-text">数据目录规划</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#配置tracker服务"><span class="toc_mobile_items-number">6.5.</span> <span class="toc_mobile_items-text">配置tracker服务</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#配置storage服务"><span class="toc_mobile_items-number">6.6.</span> <span class="toc_mobile_items-text">配置storage服务</span></a></li></ol></li><li class="toc_mobile_items-item toc_mobile_items-level-2"><a class="toc_mobile_items-link" href="#Nginx服务安装配置"><span class="toc_mobile_items-number">7.</span> <span class="toc_mobile_items-text">Nginx服务安装配置</span></a><ol class="toc_mobile_items-child"><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#下载Nginx源码包"><span class="toc_mobile_items-number">7.1.</span> <span class="toc_mobile_items-text">下载Nginx源码包</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#上传并解压Nginx源码包及fastdfs插件包"><span class="toc_mobile_items-number">7.2.</span> <span class="toc_mobile_items-text">上传并解压Nginx源码包及fastdfs插件包</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#编译Nginx准备"><span class="toc_mobile_items-number">7.3.</span> <span class="toc_mobile_items-text">编译Nginx准备</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#编译安装Nginx"><span class="toc_mobile_items-number">7.4.</span> <span class="toc_mobile_items-text">编译安装Nginx</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#注册到系统服务"><span class="toc_mobile_items-number">7.5.</span> <span class="toc_mobile_items-text">注册到系统服务</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#设置Nginx开机启动项"><span class="toc_mobile_items-number">7.6.</span> <span class="toc_mobile_items-text">设置Nginx开机启动项</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#修改Nginx配置"><span class="toc_mobile_items-number">7.7.</span> <span class="toc_mobile_items-text">修改Nginx配置</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#配置nginx的fdfs插件"><span class="toc_mobile_items-number">7.8.</span> <span class="toc_mobile_items-text">配置nginx的fdfs插件</span></a></li></ol></li><li class="toc_mobile_items-item toc_mobile_items-level-2"><a class="toc_mobile_items-link" href="#服务启动及验证"><span class="toc_mobile_items-number">8.</span> <span class="toc_mobile_items-text">服务启动及验证</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-2"><a class="toc_mobile_items-link" href="#Java客户端测试"><span class="toc_mobile_items-number">9.</span> <span class="toc_mobile_items-text">Java客户端测试</span></a><ol class="toc_mobile_items-child"><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#java项目Maven依赖"><span class="toc_mobile_items-number">9.1.</span> <span class="toc_mobile_items-text">java项目Maven依赖</span></a></li><li class="toc_mobile_items-item toc_mobile_items-level-3"><a class="toc_mobile_items-link" href="#代码测试"><span class="toc_mobile_items-number">9.2.</span> <span class="toc_mobile_items-text">代码测试</span></a></li></ol></li></ol></div></div></div><div id="body-wrap"><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div class="auto_open" id="sidebar"><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">您已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#FastDFS简介"><span class="toc-number">1.</span> <span class="toc-text">FastDFS简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#FastDFS原理介绍"><span class="toc-number">2.</span> <span class="toc-text">FastDFS原理介绍</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#文件上传"><span class="toc-number">2.1.</span> <span class="toc-text">文件上传</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#文件同步"><span class="toc-number">2.2.</span> <span class="toc-text">文件同步</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#下载文件"><span class="toc-number">2.3.</span> <span class="toc-text">下载文件</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#部署环境准备"><span class="toc-number">3.</span> <span class="toc-text">部署环境准备</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#环境说明"><span class="toc-number">3.1.</span> <span class="toc-text">环境说明</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#系统依赖"><span class="toc-number">3.2.</span> <span class="toc-text">系统依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#软件环境"><span class="toc-number">3.3.</span> <span class="toc-text">软件环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#机器及网络环境规划"><span class="toc-number">3.4.</span> <span class="toc-text">机器及网络环境规划</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#防火墙设置"><span class="toc-number">3.5.</span> <span class="toc-text">防火墙设置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Keepalived服务安装配置"><span class="toc-number">4.</span> <span class="toc-text">Keepalived服务安装配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#下载Keepalived源码包"><span class="toc-number">4.1.</span> <span class="toc-text">下载Keepalived源码包</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#上传并解压Keepalived源码包"><span class="toc-number">4.2.</span> <span class="toc-text">上传并解压Keepalived源码包</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#编译Keepalived准备"><span class="toc-number">4.3.</span> <span class="toc-text">编译Keepalived准备</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#编译安装Keepalived"><span class="toc-number">4.4.</span> <span class="toc-text">编译安装Keepalived</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#安装配置Keepalived"><span class="toc-number">4.5.</span> <span class="toc-text">安装配置Keepalived</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#设置Keepalived开机启动项"><span class="toc-number">4.6.</span> <span class="toc-text">设置Keepalived开机启动项</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#配置Keepalived服务"><span class="toc-number">4.7.</span> <span class="toc-text">配置Keepalived服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#编写nginx服务检测脚本"><span class="toc-number">4.8.</span> <span class="toc-text">编写nginx服务检测脚本</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#修改内核参数"><span class="toc-number">4.9.</span> <span class="toc-text">修改内核参数</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#安装FastDFS依赖库"><span class="toc-number">5.</span> <span class="toc-text">安装FastDFS依赖库</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#安装libevent依赖"><span class="toc-number">5.1.</span> <span class="toc-text">安装libevent依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#安装libfasttcommon依赖"><span class="toc-number">5.2.</span> <span class="toc-text">安装libfasttcommon依赖</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#安装部署Tracker服务和Storage服务"><span class="toc-number">6.</span> <span class="toc-text">安装部署Tracker服务和Storage服务</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#安装fastdfs服务"><span class="toc-number">6.1.</span> <span class="toc-text">安装fastdfs服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#fastdfs服务目录信息"><span class="toc-number">6.2.</span> <span class="toc-text">fastdfs服务目录信息</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#注册开机启动"><span class="toc-number">6.3.</span> <span class="toc-text">注册开机启动</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#数据目录规划"><span class="toc-number">6.4.</span> <span class="toc-text">数据目录规划</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#配置tracker服务"><span class="toc-number">6.5.</span> <span class="toc-text">配置tracker服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#配置storage服务"><span class="toc-number">6.6.</span> <span class="toc-text">配置storage服务</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Nginx服务安装配置"><span class="toc-number">7.</span> <span class="toc-text">Nginx服务安装配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#下载Nginx源码包"><span class="toc-number">7.1.</span> <span class="toc-text">下载Nginx源码包</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#上传并解压Nginx源码包及fastdfs插件包"><span class="toc-number">7.2.</span> <span class="toc-text">上传并解压Nginx源码包及fastdfs插件包</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#编译Nginx准备"><span class="toc-number">7.3.</span> <span class="toc-text">编译Nginx准备</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#编译安装Nginx"><span class="toc-number">7.4.</span> <span class="toc-text">编译安装Nginx</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#注册到系统服务"><span class="toc-number">7.5.</span> <span class="toc-text">注册到系统服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#设置Nginx开机启动项"><span class="toc-number">7.6.</span> <span class="toc-text">设置Nginx开机启动项</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#修改Nginx配置"><span class="toc-number">7.7.</span> <span class="toc-text">修改Nginx配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#配置nginx的fdfs插件"><span class="toc-number">7.8.</span> <span class="toc-text">配置nginx的fdfs插件</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#服务启动及验证"><span class="toc-number">8.</span> <span class="toc-text">服务启动及验证</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Java客户端测试"><span class="toc-number">9.</span> <span class="toc-text">Java客户端测试</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#java项目Maven依赖"><span class="toc-number">9.1.</span> <span class="toc-text">java项目Maven依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#代码测试"><span class="toc-number">9.2.</span> <span class="toc-text">代码测试</span></a></li></ol></li></ol></div></div></div><main id="content-outer"><div id="top-container" style="background-image:url(https://cdn.maxbill.cn/blog/img/default-post.jpg)"><div id="post-info"><div id="post-title"><div class="posttitle">分布式文件系统FastDFS安装部署(高可用)</div></div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i> 发表于 2019-11-20<span class="post-meta__separator">|</span><i class="fa fa-history fa-fw" aria-hidden="true"></i> 更新于 2020-02-16</time><span class="post-meta__separator">|</span><span><i class="fa fa-inbox post-meta__icon fa-fw" aria-hidden="true"></i><a class="post-meta__categories" href="/kinds/%E5%AD%A6%E5%88%86%E5%B8%83%E5%BC%8F/">学分布式</a></span><div class="post-meta-wordcount"><i class="fa fa-file-word-o post-meta__icon fa-fw" aria-hidden="true"></i><span>字数总计:</span><span class="word-count">4.8k</span><span class="post-meta__separator">|</span><i class="fa fa-clock-o post-meta__icon fa-fw" aria-hidden="true"></i><span>阅读时长: 22 分钟</span><div class="post-meta-pv-cv"><span class="post-meta__separator">|</span><span><i class="fa fa-eye post-meta__icon fa-fw" aria-hidden="true"> </i>阅读量:</span><span id="busuanzi_value_page_pv"></span><span class="post-meta__separator">|</span><i class="fa fa-comments-o post-meta__icon fa-fw" aria-hidden="true"></i><span>评论数:</span><a href="/4293262294.html#post-comment" itemprop="discussionUrl"><span class="valine-comment-count comment-count" data-xid="/4293262294.html" itemprop="commentCount"></span></a></div></div></div></div></div><div class="layout layout_post" id="content-inner"><article id="post"><div class="article-container" id="post-content"><p>本文会搭建一个适合低业务访问业务量的高可用的FastDFS集群环境：两个Tracker服务，一个storage group中两个storage服务节点；该方案仅适用于业务访问量较低的环境下。对于大量业务系统的高并发访问，为了保证存储系统正常工作一般的架构思路：安装多个Tracker服务(至少两个，根据业务量调整)，搭建多个storage group(至少两个，根据业务量调整)，每个storage group中多个storage node(至少两个，做数据的冗余备份，进行容灾机制，而且node必须在不同的机器上)</p><h2 id="FastDFS简介"><a href="#FastDFS简介" class="headerlink" title="FastDFS简介"></a><strong>FastDFS简介</strong></h2><p>FastDFS是一个开源的轻量级分布式文件系统，它对文件进行管理，功能包括：文件存储、文件同步、文件访问（文件上传、文件下载）等，解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务，如相册网站、视频网站等等。<br>FastDFS为互联网量身定制，充分考虑了冗余备份、负载均衡、线性扩容等机制，并注重高可用、高性能等指标，使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。FastDFS服务端有两个角色：跟踪器（tracker）和存储节点（storage）。跟踪器主要做调度工作，在访问上起负载均衡的作用。存储节点存储文件，完成文件管理的所有功能：就是这样的存储、同步和提供存取接口，FastDFS同时对文件的metadata进行管理。所谓文件的meta data就是文件的相关属性，以键值对（key value）方式表示，如：width=1024，其中的key为width，value为1024。文件metadata是文件属性列表，可以包含多个键值对。跟踪器和存储节点都可以由一台或多台服务器构成。跟踪器和存储节点中的服务器均可以随时增加或下线而不会影响线上服务。其中跟踪器中的所有服务器都是对等的，可以根据服务器的压力情况随时增加或减少。为了支持大容量，存储节点（服务器）采用了分卷（或分组）的组织方式。存储系统由一个或多个卷组成，卷与卷之间的文件是相互独立的，所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成，一个卷下的存储服务器中的文件都是相同的，卷中的多台存储服务器起到了冗余备份和负载均衡的作用。在卷中增加服务器时，同步已有的文件由系统自动完成，同步完成后，系统自动将新增服务器切换到线上提供服务。当存储空间不足或即将耗尽时，可以动态添加卷。只需要增加一台或多台服务器，并将它们配置为一个新的卷，这样就扩大了存储系统的容量。FastDFS中的文件标识分为两个部分：卷名和文件名，二者缺一不可。(简介摘自百度百科)</p><h2 id="FastDFS原理介绍"><a href="#FastDFS原理介绍" class="headerlink" title="FastDFS原理介绍"></a><strong>FastDFS原理介绍</strong></h2><h3 id="文件上传"><a href="#文件上传" class="headerlink" title="文件上传"></a>文件上传</h3><p>FastDFS以客户端库的方式提供基本的文件访问接口如upload、download、append、delete等，Storage 服务会定时的向Tracker服务发送自己的存储信息。当Tracker 服务集群中的Tracker 服务是多个时，各个Tracker服务之间的关系是对等的，因此客户端上传时会任意选择一个Trackre服务。当Tracker服务收到客户端上传文件请求时，会为该文件分配一个可以存储文件的group，当选定了group后就要决定给客户端分配group中的哪一个storage服务。当分配好storage 服务后，客户端向storage发送写文件请求，storage将会为文件分配一个数据存储目录。然后为文件分配一个文件ID标示，然后根据以上的信息生成文件名存储文件。</p><h3 id="文件同步"><a href="#文件同步" class="headerlink" title="文件同步"></a>文件同步</h3><p>上传文件后，客户端将文件写到group内的一个storage 服务即为上传文件成功，storage服务写完文件后，会由后台线程将文件同步至同group内的其他的storage 服务节点上。 每个storage服务写文件后，会同时写一份binlog，binlog里不包含文件数据，只包含文件名等元信息，这份binlog用于后台同步，storage会记录向group内其他storage同步的进度，以便重启后能接上次的进度继续同步；进度以时间戳的方式进行记录，所以最好能保证集群内的所有server的始终保持同步。最后Storage服务的同步进度会作为元数据的一部分汇报到tracker服务上，tracker服务在选择读storage的时候会以同步进度作为参考指标。</p><h3 id="下载文件"><a href="#下载文件" class="headerlink" title="下载文件"></a>下载文件</h3><p>当下载文件时，客户端先询问tracker服务下载文件的storage，参数为文件标识（卷名和文件名）；然后tracker向客户端返回一台可用的storage；最后客户端直接和storage通讯完成文件下载。</p><h2 id="部署环境准备"><a href="#部署环境准备" class="headerlink" title="部署环境准备"></a><strong>部署环境准备</strong></h2><h3 id="环境说明"><a href="#环境说明" class="headerlink" title="环境说明"></a>环境说明</h3><p>操作系统CentOS7.6<br>fastdfs版本：6.01<br>nginx版本：1.16.1<br>keepalived版本：2.0.19</p><h3 id="系统依赖"><a href="#系统依赖" class="headerlink" title="系统依赖"></a>系统依赖</h3><p>gcc gcc-c++ perl pcre pcre-devel zlib zlib-devel openssl openssl-devel libnl libnl-devel</p><h3 id="软件环境"><a href="#软件环境" class="headerlink" title="软件环境"></a>软件环境</h3><p>libevent下载地址：<a href="http://libevent.org/" target="_blank" rel="noopener">http://libevent.org/</a><br>nginx下载地址：<a href="http://nginx.org/en/download.html" target="_blank" rel="noopener">http://nginx.org/en/download.html</a><br>keepalived下载地址：<a href="https://www.keepalived.org/software/" target="_blank" rel="noopener">https://www.keepalived.org/software/</a><br>fastdfs下载地址：<a href="https://github.com/happyfish100/fastdfs/releases" target="_blank" rel="noopener">https://github.com/happyfish100/fastdfs/releases</a><br>libfasttcommon下载地址：<a href="https://github.com/happyfish100/libfastcommon/releases" target="_blank" rel="noopener">https://github.com/happyfish100/libfastcommon/releases</a><br>fastdfs-nginx-module下载地址：<a href="https://github.com/happyfish100/fastdfs-nginx-module/releases" target="_blank" rel="noopener">https://github.com/happyfish100/fastdfs-nginx-module/releases</a></p><h3 id="机器及网络环境规划"><a href="#机器及网络环境规划" class="headerlink" title="机器及网络环境规划"></a>机器及网络环境规划</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">Fdfs Server VIP：         192.168.100.110</span><br><span class="line"></span><br><span class="line">Tracker Server1：         192.168.100.111</span><br><span class="line"></span><br><span class="line">Tracker Server2：         192.168.100.112</span><br><span class="line"></span><br><span class="line">Storage Group1 Node1：    192.168.100.111</span><br><span class="line"></span><br><span class="line">Storage Group1 Node2：    192.168.100.112</span><br></pre></td></tr></table></figure></div><h3 id="防火墙设置"><a href="#防火墙设置" class="headerlink" title="防火墙设置"></a>防火墙设置</h3><p>关闭系统防火墙：sudo systemctl stop firewalld &amp;&amp; systemctl disable firewalld</p><h2 id="Keepalived服务安装配置"><a href="#Keepalived服务安装配置" class="headerlink" title="Keepalived服务安装配置"></a><strong>Keepalived服务安装配置</strong></h2><h3 id="下载Keepalived源码包"><a href="#下载Keepalived源码包" class="headerlink" title="下载Keepalived源码包"></a>下载Keepalived源码包</h3><p>官网地址：<a href="https://www.keepalived.org/" target="_blank" rel="noopener">https://www.keepalived.org/</a><br>下载地址：<a href="https://www.keepalived.org/software/keepalived-2.0.19.tar.gz" target="_blank" rel="noopener">https://www.keepalived.org/software/keepalived-2.0.19.tar.gz</a></p><h3 id="上传并解压Keepalived源码包"><a href="#上传并解压Keepalived源码包" class="headerlink" title="上传并解压Keepalived源码包"></a>上传并解压Keepalived源码包</h3><p>tar -zxvf keepalived-2.0.19.tar.gz</p><h3 id="编译Keepalived准备"><a href="#编译Keepalived准备" class="headerlink" title="编译Keepalived准备"></a>编译Keepalived准备</h3><p>进入解压目录：cd keepalived-2.0.19<br>执行编译准备：./configure –prefix=/work/keepalived<br>注意：一定要有gcc和openssl编译相关的依赖</p><h3 id="编译安装Keepalived"><a href="#编译安装Keepalived" class="headerlink" title="编译安装Keepalived"></a>编译安装Keepalived</h3><p>make &amp;&amp; make install</p><h3 id="安装配置Keepalived"><a href="#安装配置Keepalived" class="headerlink" title="安装配置Keepalived"></a>安装配置Keepalived</h3><p>keepalived启动时会从/etc/keepalived/中相关的目录下查找keepalived.conf配置文件，因此将keepalived安装录/usr/local/keepalived/etc/keepalived.conf 拷贝到/etc/keepalived/中。<br>mkdir /etc/keepalived/<br>cp /work/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf<br>cp /work/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived</p><h3 id="设置Keepalived开机启动项"><a href="#设置Keepalived开机启动项" class="headerlink" title="设置Keepalived开机启动项"></a>设置Keepalived开机启动项</h3><p>systemctl enable keepalived<br>然后就能使用systemctl start/stop/status keepalived管理keepalived了</p><h3 id="配置Keepalived服务"><a href="#配置Keepalived服务" class="headerlink" title="配置Keepalived服务"></a>配置Keepalived服务</h3><p>192.168.100.111机器上配置：vi /etc/keepalived/keepalived.conf</p><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">vrrp_script check_nginx &#123;</span><br><span class="line">       interval 3</span><br><span class="line">       script &quot;&#x2F;work&#x2F;script&#x2F;check_nginx.sh&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">vrrp_instance fdfs_server &#123;</span><br><span class="line">       state MASTER</span><br><span class="line">       interface enp0s3</span><br><span class="line">       virtual_router_id 110</span><br><span class="line">       priority 100</span><br><span class="line">       advert_int 3</span><br><span class="line">       authentication &#123;</span><br><span class="line">            auth_type PASS</span><br><span class="line">            auth_pass password</span><br><span class="line">       &#125;</span><br><span class="line">       virtual_ipaddress &#123;</span><br><span class="line">            192.168.100.110</span><br><span class="line">       &#125;</span><br><span class="line">       track_script &#123;</span><br><span class="line">            check_nginx</span><br><span class="line">       &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div><p>192.168.100.112机器上配置：vi /etc/keepalived/keepalived.conf</p><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">vrrp_script check_nginx &#123;</span><br><span class="line">       interval 3</span><br><span class="line">       script &quot;&#x2F;work&#x2F;script&#x2F;check_nginx.sh&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">vrrp_instance fdfs_server &#123;</span><br><span class="line">       state BACKUP</span><br><span class="line">       interface enp0s3</span><br><span class="line">       virtual_router_id 110</span><br><span class="line">       priority 90</span><br><span class="line">       advert_int 3</span><br><span class="line">       authentication &#123;</span><br><span class="line">            auth_type PASS</span><br><span class="line">            auth_pass password</span><br><span class="line">       &#125;</span><br><span class="line">       virtual_ipaddress &#123;</span><br><span class="line">            192.168.100.110</span><br><span class="line">       &#125;</span><br><span class="line">       track_script &#123;</span><br><span class="line">            check_nginx</span><br><span class="line">       &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div><h3 id="编写nginx服务检测脚本"><a href="#编写nginx服务检测脚本" class="headerlink" title="编写nginx服务检测脚本"></a>编写nginx服务检测脚本</h3><p>vi /work/script/check_nginx.sh</p><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">#!&#x2F;bin&#x2F;bash</span><br><span class="line">active_status&#x3D;&#96;netstat -lntp|grep nginx|wc -l&#96;</span><br><span class="line">if [ $active_status -gt 0 ]; then</span><br><span class="line">    exit 0</span><br><span class="line">else</span><br><span class="line">    exit 1</span><br><span class="line">fi</span><br></pre></td></tr></table></figure></div><p>然后给脚本赋予执行权限：chmod +x /work/script/check_nginx.sh</p><h3 id="修改内核参数"><a href="#修改内核参数" class="headerlink" title="修改内核参数"></a>修改内核参数</h3><p>vi /etc/sysctl.conf<br>增加如下内容：</p><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">net.ipv4.ip_nonlocal_bind &#x3D; 1  #允许忽视VIP的存在</span><br><span class="line">net.ipv4.ip_forward &#x3D; 1  #允许转发</span><br></pre></td></tr></table></figure></div><p>sysctl –system 使配置生效</p><h2 id="安装FastDFS依赖库"><a href="#安装FastDFS依赖库" class="headerlink" title="安装FastDFS依赖库"></a><strong>安装FastDFS依赖库</strong></h2><h3 id="安装libevent依赖"><a href="#安装libevent依赖" class="headerlink" title="安装libevent依赖"></a>安装libevent依赖</h3><p>解压libevent源码包：tar -zxvf libevent-2.1.11-stable.tar.gz<br>进入源码目录：cd libevent-2.1.11-stable<br>编译安装前配置：./configure<br>编译安装：make &amp;&amp; make install<br>默认安装位置：/usr/local/lib</p><h3 id="安装libfasttcommon依赖"><a href="#安装libfasttcommon依赖" class="headerlink" title="安装libfasttcommon依赖"></a>安装libfasttcommon依赖</h3><p>解压libfasttcommon源码包：tar -zxvf libfastcommon-1.0.41.tar.gz<br>进入源码目录：cd libfastcommon-1.0.41<br>编译安装：./make.sh &amp;&amp; ./make.sh install<br>默认安装位置：/usr/lib64</p><h2 id="安装部署Tracker服务和Storage服务"><a href="#安装部署Tracker服务和Storage服务" class="headerlink" title="安装部署Tracker服务和Storage服务"></a><strong>安装部署Tracker服务和Storage服务</strong></h2><h3 id="安装fastdfs服务"><a href="#安装fastdfs服务" class="headerlink" title="安装fastdfs服务"></a>安装fastdfs服务</h3><p>解压fastdfs源码包：tar -zxvf fastdfs-6.01.tar.gz<br>进入fastdfs源码包：cd fastdfs-6.01<br>编译安装：./make.sh &amp;&amp; ./make.sh install</p><h3 id="fastdfs服务目录信息"><a href="#fastdfs服务目录信息" class="headerlink" title="fastdfs服务目录信息"></a>fastdfs服务目录信息</h3><p>安装完成后服务及脚本拷贝到/usr/bin 目录，配置文件拷贝到/etc/fdfs目录，启动脚本拷贝到/etc/init.d/目录</p><h3 id="注册开机启动"><a href="#注册开机启动" class="headerlink" title="注册开机启动"></a>注册开机启动</h3><p>chkconfig –add fdfs_trackerd<br>chkconfig fdfs_trackerd on<br>chkconfig –add fdfs_storaged<br>chkconfig fdfs_storaged on</p><h3 id="数据目录规划"><a href="#数据目录规划" class="headerlink" title="数据目录规划"></a>数据目录规划</h3><p>创建fdfs数据主目录：mkdir /work/fdfs<br>创建tracker数据目录：mkdir /work/fdfs/tracker<br>创建storage数据目录：mkdir /work/fdfs/storage</p><h3 id="配置tracker服务"><a href="#配置tracker服务" class="headerlink" title="配置tracker服务"></a>配置tracker服务</h3><p>将/etc/fdfs目录下的tracker.conf.sample改为tracker.conf：mv tracker.conf.sample tracker.conf修改内容如下：<br>将base_path=/home/yuqing/fastdfs 改为：/work/fdfs/tracker(该目录为上面定义创建)<br>启动Tracker服务：systemctl start fdfs_trackerd</p><h3 id="配置storage服务"><a href="#配置storage服务" class="headerlink" title="配置storage服务"></a>配置storage服务</h3><p>将/etc/fdfs目录下的storage.conf.sample改为storage.conf：mv storage.conf.sample storage.conf修改内容如下：<br>base_path=/home/yuqing/fastdfs 改为：base_path=/work/fdfs/storage(该目录为上面定义创建)<br>store_path0=/home/yuqing/fastdfs 改为：store_path0=/work/fdfs/storage(该目录为上面定义创建)<br>tracker_server=192.168.209.121:22122 改为：tracker_server=192.168.100.111:22122和tracker_server=192.168.100.112:22122<br>将/etc/fdfs/torage_ids.conf.sample 为storage_ids.conf，内容修改为当前group的storage节点信息：<br>100001 group1 192.168.100.111<br>100002 group1 192.168.100.112<br>启动Storage服务：systemctl start fdfs_storaged</p><h2 id="Nginx服务安装配置"><a href="#Nginx服务安装配置" class="headerlink" title="Nginx服务安装配置"></a><strong>Nginx服务安装配置</strong></h2><h3 id="下载Nginx源码包"><a href="#下载Nginx源码包" class="headerlink" title="下载Nginx源码包"></a>下载Nginx源码包</h3><p>官网地址：<a href="http://nginx.org/" target="_blank" rel="noopener">http://nginx.org/</a><br>下载地址：<a href="http://nginx.org/en/download.html" target="_blank" rel="noopener">http://nginx.org/en/download.html</a></p><h3 id="上传并解压Nginx源码包及fastdfs插件包"><a href="#上传并解压Nginx源码包及fastdfs插件包" class="headerlink" title="上传并解压Nginx源码包及fastdfs插件包"></a>上传并解压Nginx源码包及fastdfs插件包</h3><p>tar -zxvf nginx-1.16.1.tar.gz<br>tar -zxvf fastdfs-nginx-module-1.21.tar.gz</p><h3 id="编译Nginx准备"><a href="#编译Nginx准备" class="headerlink" title="编译Nginx准备"></a>编译Nginx准备</h3><p>进入解压目录：cd nginx-1.16.1<br>拷贝fastdfs插件包到nginx源码目录：mv ../fastdfs-nginx-module-1.21 .<br>执行编译准备：./configure –prefix=/work/nginx \–with-stream \–add-module=fastdfs-nginx-module-1.21/src<br>注意：一定要有gcc和openssl编译相关的依赖</p><h3 id="编译安装Nginx"><a href="#编译安装Nginx" class="headerlink" title="编译安装Nginx"></a>编译安装Nginx</h3><p>make &amp;&amp; make install</p><h3 id="注册到系统服务"><a href="#注册到系统服务" class="headerlink" title="注册到系统服务"></a>注册到系统服务</h3><p>vi /usr/lib/systemd/system/nginx.service</p><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line">Description&#x3D;nginx</span><br><span class="line">Documentation&#x3D;http:&#x2F;&#x2F;nginx.org&#x2F;en&#x2F;docs&#x2F;</span><br><span class="line">After&#x3D;network.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type&#x3D;forking</span><br><span class="line">PIDFile&#x3D;&#x2F;work&#x2F;nginx&#x2F;logs&#x2F;nginx.pid</span><br><span class="line">ExecStartPre&#x3D;&#x2F;work&#x2F;nginx&#x2F;sbin&#x2F;nginx -t -c &#x2F;work&#x2F;nginx&#x2F;conf&#x2F;nginx.conf</span><br><span class="line">ExecStart&#x3D;&#x2F;work&#x2F;nginx&#x2F;sbin&#x2F;nginx -c &#x2F;work&#x2F;nginx&#x2F;conf&#x2F;nginx.conf</span><br><span class="line">ExecReload&#x3D;&#x2F;bin&#x2F;kill -s HUP $MAINPID</span><br><span class="line">ExecStop&#x3D;&#x2F;bin&#x2F;kill -s QUIT $MAINPID</span><br><span class="line">PrivateTmp&#x3D;true</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy&#x3D;multi-user.target</span><br></pre></td></tr></table></figure></div><h3 id="设置Nginx开机启动项"><a href="#设置Nginx开机启动项" class="headerlink" title="设置Nginx开机启动项"></a>设置Nginx开机启动项</h3><p>systemctl enable nginx<br>然后就能使用systemctl start/stop/status nginx管理nginx了</p><h3 id="修改Nginx配置"><a href="#修改Nginx配置" class="headerlink" title="修改Nginx配置"></a>修改Nginx配置</h3><p>vi /work/nginx/conf/nginx.conf</p><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line">#user  nobody;</span><br><span class="line">worker_processes  1;</span><br><span class="line">#error_log  logs&#x2F;error.log;</span><br><span class="line">#error_log  logs&#x2F;error.log  notice;</span><br><span class="line">#error_log  logs&#x2F;error.log  info;</span><br><span class="line">#pid        logs&#x2F;nginx.pid;</span><br><span class="line"></span><br><span class="line">events &#123;</span><br><span class="line">    worker_connections  1024;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">stream &#123;</span><br><span class="line"></span><br><span class="line">    upstream tracker &#123;</span><br><span class="line">         server 192.168.100.111:22122 weight&#x3D;1 max_fails&#x3D;2 fail_timeout&#x3D;10s;</span><br><span class="line">         server 192.168.100.112:22122 weight&#x3D;1 max_fails&#x3D;2 fail_timeout&#x3D;10s;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    server &#123;</span><br><span class="line">        listen       7777;</span><br><span class="line">        proxy_timeout 5m;</span><br><span class="line">        proxy_pass tracker;</span><br><span class="line">        proxy_connect_timeout 10s;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">http &#123;</span><br><span class="line"></span><br><span class="line">    include       mime.types;</span><br><span class="line">    default_type  application&#x2F;octet-stream;</span><br><span class="line">    sendfile        on;</span><br><span class="line">    keepalive_timeout  65;</span><br><span class="line"></span><br><span class="line">    upstream storage &#123;</span><br><span class="line">         server 192.168.100.111:8888 weight&#x3D;1 max_fails&#x3D;2 fail_timeout&#x3D;10s;</span><br><span class="line">         server 192.168.100.112:8888 weight&#x3D;1 max_fails&#x3D;2 fail_timeout&#x3D;10s;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    server &#123;</span><br><span class="line">        listen       80;</span><br><span class="line">        server_name  localhost;</span><br><span class="line">        </span><br><span class="line">        location &#x2F;group1 &#123;</span><br><span class="line">            proxy_pass         http:&#x2F;&#x2F;storage;</span><br><span class="line">            proxy_set_header   Host             $host;</span><br><span class="line">            proxy_set_header   X-Real-IP        $remote_addr;</span><br><span class="line">            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        error_page   500 502 503 504  &#x2F;50x.html;</span><br><span class="line">        location &#x3D; &#x2F;50x.html &#123;</span><br><span class="line">            root   html;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    server &#123;</span><br><span class="line">        listen       8888;</span><br><span class="line">        server_name  localhost;</span><br><span class="line"></span><br><span class="line">        location &#x2F; &#123;</span><br><span class="line">            alias &#x2F;work&#x2F;fdfs&#x2F;storage&#x2F;data&#x2F;;</span><br><span class="line">            ngx_fastdfs_module;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div><h3 id="配置nginx的fdfs插件"><a href="#配置nginx的fdfs插件" class="headerlink" title="配置nginx的fdfs插件"></a>配置nginx的fdfs插件</h3><p>将/etc/fdfs下的http.conf.sample和mime.types.sample重命名为：http.conf和mime.types<br>将fastdfs-nginx-module-1.21/src下的mod_fastdfs.conf拷贝到/etc/fdfs下<br>修改mod_fastdfs.conf如下：<br>连接超时时间： connect_timeout=5<br>Tracker服务地址：tracker_server=192.168.100.111:22122 和tracker_server=192.168.100.112:22122<br>Storage服务端口：storage\server_port=23000<br>如果文件ID的uri中包含/group**，则要设置为true：url_have_group_name = true<br>Storage配置的store_path0路径，必须和storage.conf中的一致：store_path0=/work/fdfs/storage<br>其他详细配置如下：</p><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br></pre></td><td class="code"><pre><span class="line"># connect timeout in seconds</span><br><span class="line"># default value is 30s</span><br><span class="line">connect_timeout&#x3D;5</span><br><span class="line"></span><br><span class="line"># network recv and send timeout in seconds</span><br><span class="line"># default value is 30s</span><br><span class="line">network_timeout&#x3D;10</span><br><span class="line"></span><br><span class="line"># the base path to store log files</span><br><span class="line">base_path&#x3D;&#x2F;work&#x2F;fdfs&#x2F;storage</span><br><span class="line"></span><br><span class="line"># if load FastDFS parameters from tracker server</span><br><span class="line"># since V1.12</span><br><span class="line"># default value is false</span><br><span class="line">load_fdfs_parameters_from_tracker&#x3D;true</span><br><span class="line"></span><br><span class="line"># storage sync file max delay seconds</span><br><span class="line"># same as tracker.conf</span><br><span class="line"># valid only when load_fdfs_parameters_from_tracker is false</span><br><span class="line"># since V1.12</span><br><span class="line"># default value is 86400 seconds (one day)</span><br><span class="line">storage_sync_file_max_delay &#x3D; 86400</span><br><span class="line"></span><br><span class="line"># if use storage ID instead of IP address</span><br><span class="line"># same as tracker.conf</span><br><span class="line"># valid only when load_fdfs_parameters_from_tracker is false</span><br><span class="line"># default value is false</span><br><span class="line"># since V1.13</span><br><span class="line">use_storage_id &#x3D; false</span><br><span class="line"></span><br><span class="line"># specify storage ids filename, can use relative or absolute path</span><br><span class="line"># same as tracker.conf</span><br><span class="line"># valid only when load_fdfs_parameters_from_tracker is false</span><br><span class="line"># since V1.13</span><br><span class="line">storage_ids_filename &#x3D; storage_ids.conf</span><br><span class="line"></span><br><span class="line"># FastDFS tracker_server can ocur more than once, and tracker_server format is</span><br><span class="line">#  &quot;host:port&quot;, host can be hostname or ip address</span><br><span class="line"># valid only when load_fdfs_parameters_from_tracker is true</span><br><span class="line">tracker_server&#x3D;192.168.100.111:22122</span><br><span class="line">tracker_server&#x3D;192.168.100.112:22122</span><br><span class="line"></span><br><span class="line"># the port of the local storage server</span><br><span class="line"># the default value is 23000</span><br><span class="line">storage_server_port&#x3D;23000</span><br><span class="line"></span><br><span class="line"># the group name of the local storage server</span><br><span class="line">group_name&#x3D;group1</span><br><span class="line"></span><br><span class="line"># if the url &#x2F; uri including the group name</span><br><span class="line"># set to false when uri like &#x2F;M00&#x2F;00&#x2F;00&#x2F;xxx</span><br><span class="line"># set to true when uri like $&#123;group_name&#125;&#x2F;M00&#x2F;00&#x2F;00&#x2F;xxx, such as group1&#x2F;M00&#x2F;xxx</span><br><span class="line"># default value is false</span><br><span class="line">url_have_group_name &#x3D; true</span><br><span class="line"></span><br><span class="line"># path(disk or mount point) count, default value is 1</span><br><span class="line"># must same as storage.conf</span><br><span class="line">store_path_count&#x3D;1</span><br><span class="line"></span><br><span class="line"># store_path#, based 0, if store_path0 not exists, it&#39;s value is base_path</span><br><span class="line"># the paths must be exist</span><br><span class="line"># must same as storage.conf</span><br><span class="line">store_path0&#x3D;&#x2F;work&#x2F;fdfs&#x2F;storage</span><br><span class="line"></span><br><span class="line"># standard log level as syslog, case insensitive, value list:</span><br><span class="line">### emerg for emergency</span><br><span class="line">### alert</span><br><span class="line">### crit for critical</span><br><span class="line">### error</span><br><span class="line">### warn for warning</span><br><span class="line">### notice</span><br><span class="line">### info</span><br><span class="line">### debug</span><br><span class="line">log_level&#x3D;info</span><br><span class="line"></span><br><span class="line"># set the log filename, such as &#x2F;usr&#x2F;local&#x2F;apache2&#x2F;logs&#x2F;mod_fastdfs.log</span><br><span class="line"># empty for output to stderr (apache and nginx error_log file)</span><br><span class="line">log_filename&#x3D;</span><br><span class="line"></span><br><span class="line"># response mode when the file not exist in the local file system</span><br><span class="line">## proxy: get the content from other storage server, then send to client</span><br><span class="line">## redirect: redirect to the original storage server (HTTP Header is Location)</span><br><span class="line">response_mode&#x3D;proxy</span><br><span class="line"></span><br><span class="line"># the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a</span><br><span class="line"># multi aliases split by comma. empty value means auto set by OS type</span><br><span class="line"># this paramter used to get all ip address of the local host</span><br><span class="line"># default values is empty</span><br><span class="line">if_alias_prefix&#x3D;</span><br><span class="line"></span><br><span class="line"># use &quot;#include&quot; directive to include HTTP config file</span><br><span class="line"># NOTE: #include is an include directive, do NOT remove the # before include</span><br><span class="line">#include http.conf</span><br><span class="line"></span><br><span class="line"># if support flv</span><br><span class="line"># default value is false</span><br><span class="line"># since v1.15</span><br><span class="line">flv_support &#x3D; true</span><br><span class="line"></span><br><span class="line"># flv file extension name</span><br><span class="line"># default value is flv</span><br><span class="line"># since v1.15</span><br><span class="line">flv_extension &#x3D; flv</span><br><span class="line"></span><br><span class="line"># set the group count</span><br><span class="line"># set to none zero to support multi-group on this storage server</span><br><span class="line"># set to 0  for single group only</span><br><span class="line"># groups settings section as [group1], [group2], ..., [groupN]</span><br><span class="line"># default value is 0</span><br><span class="line"># since v1.14</span><br><span class="line">group_count &#x3D; 1</span><br><span class="line"></span><br><span class="line"># group settings for group #1</span><br><span class="line"># since v1.14</span><br><span class="line"># when support multi-group on this storage server, uncomment following section</span><br><span class="line">[group1]</span><br><span class="line">group_name&#x3D;group1</span><br><span class="line">storage_server_port&#x3D;23000</span><br><span class="line">store_path_count&#x3D;1</span><br><span class="line">store_path0&#x3D;&#x2F;work&#x2F;fdfs&#x2F;storage</span><br><span class="line"></span><br><span class="line"># group settings for group #2</span><br><span class="line"># since v1.14</span><br><span class="line"># when support multi-group, uncomment following section as neccessary</span><br><span class="line">#[group2]</span><br><span class="line">#group_name&#x3D;group2</span><br><span class="line">#storage_server_port&#x3D;23000</span><br><span class="line">#store_path_count&#x3D;1</span><br><span class="line">#store_path0&#x3D;&#x2F;home&#x2F;yuqing&#x2F;fastdfs</span><br></pre></td></tr></table></figure></div><h2 id="服务启动及验证"><a href="#服务启动及验证" class="headerlink" title="服务启动及验证"></a><strong>服务启动及验证</strong></h2><p>分别启动keepalive、nginx、tracker、storage服务<br>查看服务是否正常服务：<br><a href="https://oscimg.oschina.net/oscnet/0e39fd8468a028040406cce85bde48b5586.png" target="_blank" rel="noopener" data-fancybox="group" data-caption class="fancybox"><img alt data-src="https://oscimg.oschina.net/oscnet/0e39fd8468a028040406cce85bde48b5586.png" src="https://cdn.maxbill.cn/blog/img/loading.gif" class="lazyload"></a><br>在任意Storage机器上查看集群状态：fdfs_monitor /etc/fdfs/storage.conf<br><a href="https://oscimg.oschina.net/oscnet/fda6e27aedde1ebc7a92d3db5af2048e9e9.png" target="_blank" rel="noopener" data-fancybox="group" data-caption class="fancybox"><img alt data-src="https://oscimg.oschina.net/oscnet/fda6e27aedde1ebc7a92d3db5af2048e9e9.png" src="https://cdn.maxbill.cn/blog/img/loading.gif" class="lazyload"></a></p><h2 id="Java客户端测试"><a href="#Java客户端测试" class="headerlink" title="Java客户端测试"></a><strong>Java客户端测试</strong></h2><h3 id="java项目Maven依赖"><a href="#java项目Maven依赖" class="headerlink" title="java项目Maven依赖"></a>java项目Maven依赖</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line">项目地址：https:&#x2F;&#x2F;github.com&#x2F;tobato&#x2F;FastDFS_Client</span><br><span class="line">目前客户端主要依赖于SpringBoot，因此必须引入:</span><br><span class="line">&lt;parent&gt;</span><br><span class="line">       &lt;groupId&gt;org.springframework.boot&lt;&#x2F;groupId&gt;</span><br><span class="line">       &lt;artifactId&gt;spring-boot-starter-parent&lt;&#x2F;artifactId&gt;</span><br><span class="line">       &lt;version&gt;2.0.0.RELEASE&lt;&#x2F;version&gt;</span><br><span class="line">       &lt;relativePath&#x2F;&gt;</span><br><span class="line">&lt;&#x2F;parent&gt;</span><br><span class="line"></span><br><span class="line">FastDFS 依赖包：</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;com.github.tobato&lt;&#x2F;groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;fastdfs-client&lt;&#x2F;artifactId&gt;</span><br><span class="line">        &lt;version&gt;1.26.7&lt;&#x2F;version&gt;</span><br><span class="line">&lt;&#x2F;dependency&gt;</span><br><span class="line"></span><br><span class="line">将FastDFS引入项目：</span><br><span class="line">@Import(FdfsClientConfig.class)</span><br><span class="line"></span><br><span class="line">在application.yml当中配置Fdfs相关参数：</span><br><span class="line">fdfs:</span><br><span class="line">  pool:</span><br><span class="line">    #连接池最大数量</span><br><span class="line">    max-total: 200</span><br><span class="line">    #每个tracker地址的最大连接数</span><br><span class="line">    max-total-per-key: 50</span><br><span class="line">    #连接耗尽时等待获取连接的最大毫秒数</span><br><span class="line">    max-wait-millis: 5000</span><br><span class="line">  so-timeout: 1500</span><br><span class="line">  connect-timeout: 600</span><br><span class="line">  thumb-image:</span><br><span class="line">    width: 150</span><br><span class="line">    height: 150</span><br><span class="line">  tracker-list:</span><br><span class="line">    - 192.168.100.110:7777</span><br><span class="line"></span><br><span class="line">或者</span><br><span class="line">fdfs:</span><br><span class="line">  pool:</span><br><span class="line">    #连接池最大数量</span><br><span class="line">    max-total: 200</span><br><span class="line">    #每个tracker地址的最大连接数</span><br><span class="line">    max-total-per-key: 50</span><br><span class="line">    #连接耗尽时等待获取连接的最大毫秒数</span><br><span class="line">    max-wait-millis: 5000</span><br><span class="line">  so-timeout: 1500</span><br><span class="line">  connect-timeout: 600</span><br><span class="line">  thumb-image:</span><br><span class="line">    width: 150</span><br><span class="line">    height: 150</span><br><span class="line">  tracker-list:</span><br><span class="line">    - 192.168.100.111:22122</span><br><span class="line">    - 192.168.100.112:22122</span><br><span class="line"></span><br><span class="line">使用接口服务对Fdfs服务端进行操作，主要接口包括：</span><br><span class="line">TrackerClient - TrackerServer接口</span><br><span class="line">GenerateStorageClient - 一般文件存储接口 (StorageServer接口)</span><br><span class="line">FastFileStorageClient - 为方便项目开发集成的简单接口(StorageServer接口)</span><br><span class="line">AppendFileStorageClient - 支持文件续传操作的接口 (StorageServer接口)</span><br></pre></td></tr></table></figure></div><h3 id="代码测试"><a href="#代码测试" class="headerlink" title="代码测试"></a>代码测试</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i></div><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.maxbill;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.github.tobato.fastdfs.FdfsClientConfig;</span><br><span class="line"><span class="keyword">import</span> com.github.tobato.fastdfs.domain.fdfs.MetaData;</span><br><span class="line"><span class="keyword">import</span> com.github.tobato.fastdfs.domain.fdfs.StorePath;</span><br><span class="line"><span class="keyword">import</span> com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray;</span><br><span class="line"><span class="keyword">import</span> com.github.tobato.fastdfs.service.FastFileStorageClient;</span><br><span class="line"><span class="keyword">import</span> lombok.extern.log4j.Log4j2;</span><br><span class="line"><span class="keyword">import</span> org.apache.commons.lang3.StringUtils;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Import;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.annotation.PostConstruct;</span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line"><span class="keyword">import</span> java.text.DateFormat;</span><br><span class="line"><span class="keyword">import</span> java.text.SimpleDateFormat;</span><br><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Log</span>4j2</span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@Import</span>(FdfsClientConfig<span class="class">.<span class="keyword">class</span>)</span></span><br><span class="line"><span class="class"><span class="title">public</span> <span class="title">class</span> <span class="title">FdfsClientUtil</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> String BASE_URL = <span class="string">"http://192.168.100.110:8888/"</span>;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> FastFileStorageClient storageClient;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> FdfsClientUtil fdfsClientUtil;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@PostConstruct</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">init</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        fdfsClientUtil = <span class="keyword">this</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 文件上传</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> file    文件信息</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> infoMap 文件扩展信息</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 上传路径</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> Map&lt;String, Object&gt; <span class="title">uploadFile</span><span class="params">(File file, Map&lt;String, String&gt; infoMap)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            String fileName = file.getName();</span><br><span class="line">            String fileType = fileName.substring(fileName.lastIndexOf(<span class="string">"\\"</span>) + <span class="number">1</span>);</span><br><span class="line">            <span class="comment">//String fileType = FilenameUtils.getExtension(file.getName())</span></span><br><span class="line">            log.info(<span class="string">"[fdfs-upload]-start upload file ... "</span>);</span><br><span class="line">            log.info(<span class="string">"[fdfs-upload]-request upload file name: &#123;&#125;"</span>, fileName);</span><br><span class="line">            log.info(<span class="string">"[fdfs-upload]-request upload file info: &#123;&#125;"</span>, infoMap);</span><br><span class="line">            StorePath path = fdfsClientUtil.storageClient.uploadFile(<span class="keyword">new</span> FileInputStream(file), file.length(), fileType, getMetaData(infoMap));</span><br><span class="line">            log.info(<span class="string">"[fdfs-upload]-upload success path: &#123;&#125;"</span>, path.getFullPath());</span><br><span class="line">            <span class="keyword">return</span> getResultMap(BASE_URL.concat(path.getFullPath()), <span class="keyword">null</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            log.error(<span class="string">"[fdfs-upload]-upload file exception info: &#123;&#125;"</span>, e.getMessage());</span><br><span class="line">            <span class="keyword">return</span> getResultMap(<span class="keyword">null</span>, e.getMessage());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 下载文件</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> filePath 文件路径标识</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 文件字节</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> Map&lt;String, Object&gt; <span class="title">downloadFile</span><span class="params">(String filePath)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            filePath = filePath.replace(BASE_URL, <span class="string">""</span>);</span><br><span class="line">            StorePath storePath = StorePath.parseFromUrl(filePath);</span><br><span class="line">            String group = storePath.getGroup();</span><br><span class="line">            String path = storePath.getPath();</span><br><span class="line">            log.info(<span class="string">"[fdfs-download]-start download file ... "</span>);</span><br><span class="line">            log.info(<span class="string">"[fdfs-download]-request download file group: &#123;&#125;"</span>, group);</span><br><span class="line">            log.info(<span class="string">"[fdfs-download]-request download file path: &#123;&#125;"</span>, path);</span><br><span class="line">            <span class="keyword">byte</span>[] data = fdfsClientUtil.storageClient.downloadFile(group, path, <span class="keyword">new</span> DownloadByteArray());</span><br><span class="line">            log.info(<span class="string">"[fdfs-download]-request download file success ... "</span>);</span><br><span class="line">            <span class="keyword">return</span> getResultMap(data, <span class="keyword">null</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            log.error(<span class="string">"[fdfs-download]-download file exception info: &#123;&#125;"</span>, e.getMessage());</span><br><span class="line">            <span class="keyword">return</span> getResultMap(<span class="keyword">null</span>, e.getMessage());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 删除文件</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> filePath 文件路径标识</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 操作结果</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">deleteFile</span><span class="params">(String filePath)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            filePath = filePath.replace(BASE_URL, <span class="string">""</span>);</span><br><span class="line">            StorePath storePath = StorePath.parseFromUrl(filePath);</span><br><span class="line">            String group = storePath.getGroup();</span><br><span class="line">            String path = storePath.getPath();</span><br><span class="line">            log.info(<span class="string">"[fdfs-delete]-start delete file ... "</span>);</span><br><span class="line">            log.info(<span class="string">"[fdfs-delete]-request delete file group: &#123;&#125;"</span>, group);</span><br><span class="line">            log.info(<span class="string">"[fdfs-delete]-request delete file path: &#123;&#125;"</span>, path);</span><br><span class="line">            fdfsClientUtil.storageClient.deleteFile(storePath.getGroup(), storePath.getPath());</span><br><span class="line">            log.info(<span class="string">"[fdfs-delete]-request delete file success ... "</span>);</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            log.error(<span class="string">"[fdfs-delete]-delete file exception info: &#123;&#125;"</span>, e.getMessage());</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 查看文件元信息</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> filePath 文件路径标识</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 文件信息</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> Map&lt;String, Object&gt; <span class="title">getFileInfo</span><span class="params">(String filePath)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            filePath = filePath.replace(BASE_URL, <span class="string">""</span>);</span><br><span class="line">            StorePath storePath = StorePath.parseFromUrl(filePath);</span><br><span class="line">            String group = storePath.getGroup();</span><br><span class="line">            String path = storePath.getPath();</span><br><span class="line">            log.info(<span class="string">"[fdfs-meta]-start meta file ... "</span>);</span><br><span class="line">            log.info(<span class="string">"[fdfs-meta]-request meta file group: &#123;&#125;"</span>, group);</span><br><span class="line">            log.info(<span class="string">"[fdfs-meta]-request meta file path: &#123;&#125;"</span>, path);</span><br><span class="line">            Map&lt;String, String&gt; infoMap = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">            infoMap.put(<span class="string">"createPath"</span>, filePath);</span><br><span class="line">            Set&lt;MetaData&gt; metaData = fdfsClientUtil.storageClient.getMetadata(storePath.getGroup(), storePath.getPath());</span><br><span class="line">            log.info(<span class="string">"[fdfs-meta]-request meta file success ... "</span>);</span><br><span class="line">            <span class="keyword">if</span> (<span class="keyword">null</span> != metaData &amp;&amp; !metaData.isEmpty()) &#123;</span><br><span class="line">                metaData.forEach(meta -&gt; &#123;</span><br><span class="line">                    infoMap.put(meta.getName(), meta.getValue());</span><br><span class="line">                &#125;);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> getResultMap(infoMap, <span class="keyword">null</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            log.error(<span class="string">"[fdfs-meta]-meta file exception info: &#123;&#125;"</span>, e.getMessage());</span><br><span class="line">            <span class="keyword">return</span> getResultMap(<span class="keyword">null</span>, e.getMessage());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 封装附件元信息</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> infoMap 自定义数据</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 附件元信息</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> Set&lt;MetaData&gt; <span class="title">getMetaData</span><span class="params">(Map&lt;String, String&gt; infoMap)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (<span class="keyword">null</span> != infoMap &amp;&amp; !infoMap.isEmpty()) &#123;</span><br><span class="line">            Set&lt;MetaData&gt; metaDataSet = <span class="keyword">new</span> HashSet&lt;&gt;();</span><br><span class="line">            <span class="keyword">for</span> (String key : infoMap.keySet()) &#123;</span><br><span class="line">                metaDataSet.add(<span class="keyword">new</span> MetaData(key, infoMap.get(key)));</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> metaDataSet;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            DateFormat df = <span class="keyword">new</span> SimpleDateFormat(<span class="string">"yyyy-MM-dd HH:mm:ss"</span>);</span><br><span class="line">            Set&lt;MetaData&gt; metaDataSet = <span class="keyword">new</span> HashSet&lt;&gt;();</span><br><span class="line">            metaDataSet.add(<span class="keyword">new</span> MetaData(<span class="string">"createUser"</span>, <span class="string">"MaxBill"</span>));</span><br><span class="line">            metaDataSet.add(<span class="keyword">new</span> MetaData(<span class="string">"createDate"</span>, df.format(<span class="keyword">new</span> Date())));</span><br><span class="line">            <span class="keyword">return</span> metaDataSet;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 封装结果信息</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> data 数据</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> info 信息</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 操作结果</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> Map&lt;String, Object&gt; <span class="title">getResultMap</span><span class="params">(Object data, String info)</span> </span>&#123;</span><br><span class="line">        Map&lt;String, Object&gt; resultMap = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">        <span class="keyword">if</span> (StringUtils.isEmpty(info)) &#123;</span><br><span class="line">            resultMap.put(<span class="string">"flag"</span>, <span class="keyword">true</span>);</span><br><span class="line">            resultMap.put(<span class="string">"data"</span>, data);</span><br><span class="line">            resultMap.put(<span class="string">"info"</span>, <span class="string">"success"</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            resultMap.put(<span class="string">"flag"</span>, <span class="keyword">false</span>);</span><br><span class="line">            resultMap.put(<span class="string">"info"</span>, info);</span><br><span class="line">            resultMap.put(<span class="string">"data"</span>, <span class="keyword">null</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> resultMap;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div></div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">MaxBill</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.maxbill.cn/4293262294.html">https://www.maxbill.cn/4293262294.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.maxbill.cn">MaxBill</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/marks/FastDFS/">FastDFS </a><a class="post-meta__tags" href="/marks/%E5%88%86%E5%B8%83%E5%BC%8F%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F/">分布式文件系统 </a><a class="post-meta__tags" href="/marks/%E9%AB%98%E5%8F%AF%E7%94%A8/">高可用</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.maxbill.cn/post/cover/fastdfs.jpg" data-sites="wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.bootcss.com/social-share.js/1.0.16/css/share.min.css"><script src="https://cdn.bootcss.com/social-share.js/1.0.16/js/social-share.min.js"></script></div></div><div class="post-reward"><a class="reward-button button--primary button--animated"><i class="fa fa-qrcode"></i> 打赏<div class="reward-main"><ul class="reward-all"><li class="reward-item"><img class="lazyload post-qr-code__img" src="https://cdn.maxbill.cn/blog/img/wechat.png" alt="微信"><div class="post-qr-code__desc">微信</div></li><li class="reward-item"><img class="lazyload post-qr-code__img" src="https://cdn.maxbill.cn/blog/img/alipay.png" alt="支付宝"><div class="post-qr-code__desc">支付宝</div></li></ul></div></a></div><nav class="pagination_post" id="pagination"><div class="prev-post pull_left"><a href="/3439513514.html"><img class="prev_cover lazyload" data-src="https://cdn.maxbill.cn/post/cover/hexo.jpg" onerror='onerror=null,src="https://cdn.maxbill.cn/blog/img/post-404.png"'><div class="label">上一篇</div><div class="prev_info"><span>使用Hexo写第一篇文章</span></div></a></div><div class="next-post pull_right"><a href="/2128340410.html"><img class="next_cover lazyload" data-src="https://cdn.maxbill.cn/post/cover/fastdfs.jpg" onerror='onerror=null,src="https://cdn.maxbill.cn/blog/img/post-404.png"'><div class="label">下一篇</div><div class="next_info"><span>分布式文件系统FastDFS安装部署(非高可用)</span></div></a></div></nav><div class="relatedPosts"><div class="relatedPosts_headline"><i class="fa fa-fw fa-thumbs-up" aria-hidden="true"></i><span> 相关推荐</span></div><div class="relatedPosts_list"><div class="relatedPosts_item"><a href="/2128340410.html" title="分布式文件系统FastDFS安装部署(非高可用)"><img class="relatedPosts_cover lazyload" data-src="https://cdn.maxbill.cn/post/cover/fastdfs.jpg"><div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i> 2019-11-18</div><div class="relatedPosts_title">分布式文件系统FastDFS安装部署(非高可用)</div></div></a></div><div class="relatedPosts_item"><a href="/3224700853.html" title="Hadoop(02)-使用JavaApi对HDFS进行基本操作"><img class="relatedPosts_cover lazyload" data-src="https://cdn.maxbill.cn/post/cover/hadoop.jpg"><div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i> 2017-11-16</div><div class="relatedPosts_title">Hadoop(02)-使用JavaApi对HDFS进行基本操作</div></div></a></div><div class="relatedPosts_item"><a href="/3609085320.html" title="Hadoop(01)-Windows平台下Hadoop环境搭建"><img class="relatedPosts_cover lazyload" data-src="https://cdn.maxbill.cn/post/cover/hadoop.jpg"><div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i> 2017-11-13</div><div class="relatedPosts_title">Hadoop(01)-Windows平台下Hadoop环境搭建</div></div></a></div><div class="relatedPosts_item"><a href="/2830891998.html" title="K8S(03)模拟生产环境搭建高可用集群之Master节点高可用方案"><img class="relatedPosts_cover lazyload" data-src="https://cdn.maxbill.cn/post/cover/kubernetes.jpg"><div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i> 2019-10-29</div><div class="relatedPosts_title">K8S(03)模拟生产环境搭建高可用集群之Master节点高可用方案</div></div></a></div><div class="relatedPosts_item"><a href="/1686052618.html" title="K8S(01)模拟生产环境搭建高可用集群之环境规划和基础准备"><img class="relatedPosts_cover lazyload" data-src="https://cdn.maxbill.cn/post/cover/kubernetes.jpg"><div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i> 2019-10-27</div><div class="relatedPosts_title">K8S(01)模拟生产环境搭建高可用集群之环境规划和基础准备</div></div></a></div></div><div class="clear_both"></div></div><hr><div id="post-comment"><div class="comment_headling"><i class="fa fa-comments fa-fw" aria-hidden="true"></i><span> 评论</span></div><div class="vcomment" id="vcomment"></div><script src="https://cdn.maxbill.cn/blog/js/valine.min.js"></script><script>var notify=!1,verify=!0,GUEST_INFO=["nick","mail","link"],guest_info="nick,mail,link".split(",").filter(function(i){return GUEST_INFO.indexOf(i)>-1});guest_info=0==guest_info.length?GUEST_INFO:guest_info,window.valine=new Valine({el:"#vcomment",notify:notify,verify:verify,appId:"vSox9eb129uxgnXcTpFN9AAY-gzGzoHsz",appKey:"YrzpUxJzBtwhyhykDXfdHtPg",placeholder:"请留下你们的脚印^_^",avatar:"monsterid",guest_info:guest_info,pageSize:"10",lang:"zh-cn",recordIP:!0})</script></div></div></main><footer id="footer" style="background-image:url(https://cdn.maxbill.cn/blog/img/default-post.jpg)" data-type="photo"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2020 By MaxBill</div><div class="framework-info"><span>驱动 </span><a href="http://hexo.io" target="_blank" rel="noopener"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 </span><a href="https://github.com/jerryc127/hexo-theme-butterfly" target="_blank" rel="noopener"><span>Butterfly</span></a></div><div class="footer_custom_text">本站版权归作者所有，欢迎转载，但未经作者同意必须在文章页面给出原文链接，否则保留追究法律责任的权利。</div><div class="icp"><a href="http://www.beian.miit.gov.cn" target="_blank" rel="noopener"><img class="icp-icon" src="https://cdn.maxbill.cn/blog/img/icp.png"><span>未备案（暂无备案号）</span></a></div></div></footer></div><section class="rightside" id="rightside"><div id="rightside-config-hide"><i class="fa fa-book" id="readmode" title="阅读模式"></i><i class="fa fa-plus" id="font_plus" title="放大字体"></i><i class="fa fa-minus" id="font_minus" title="缩小字体"></i><a class="translate_chn_to_cht" id="translateLink" href="javascript:translatePage();" title="简繁转换" target="_self">繁</a><i class="darkmode fa fa-moon-o" id="darkmode" title="夜间模式"></i></div><div id="rightside-config-show"><div id="rightside_config" title="设置"><i class="fa fa-cog" aria-hidden="true"></i></div><a id="to_comment" href="#post-comment" title="直达评论"><i class="scroll_to_comment fa fa-comments"></i></a><i class="fa fa-list-ul close" id="mobile-toc-button" title="目录" aria-hidden="true"></i><i class="fa fa-arrow-up" id="go-up" title="回到顶部" aria-hidden="true"></i></div></section><script src="https://cdn.maxbill.cn/blog/js/jquery.min.js"></script><script src="https://cdn.maxbill.cn/blog/js/utils.js"></script><script src="https://cdn.maxbill.cn/blog/js/main.js"></script><script src="https://cdn.maxbill.cn/blog/js/tw-cn.js"></script><script src="https://cdn.maxbill.cn/blog/js/fancybox.min.js"></script><script src="https://cdn.maxbill.cn/blog/js/snackbar.min.js"></script><script id="canvas_nest" color="0,0,255" opacity="0.7" zindex="-1" count="99" mobile="false" src="https://cdn.maxbill.cn/blog/js/canvas-nest.js"></script><script async src="https://cdn.maxbill.cn/blog/js/busuanzi.mini.js"></script><script src="https://cdn.maxbill.cn/blog/js/instantpage.min.js" type="module"></script><script src="https://cdn.maxbill.cn/blog/js/lazysizes.min.js" async></script><script src="https://cdn.maxbill.cn/blog/js/click-heart.js"></script><div class="search-dialog" id="local-search"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章"></div></div></div><hr><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a href="https://github.com/wzpan/hexo-generator-search" target="_blank" rel="noopener" style="color:#49B1F5">hexo-generator-search</a> <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fa fa-times"></i></span></div><div class="search-mask"></div></body></html><!-- rebuild by neat -->